<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="家长姓名" prop="parentRealName">
        <el-input
          v-model="queryParams.parentRealName"
          placeholder="请输入家长姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="家长手机号" prop="parentPhoneNumber">
        <el-input
          v-model="queryParams.parentPhoneNumber"
          placeholder="请输入家长手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="家长身份证" prop="parentIdCar">
        <el-input
          v-model="queryParams.parentIdCar"
          placeholder="请输入家长身份证"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="孩子姓名" prop="childRealName">
        <el-input
          v-model="queryParams.childRealName"
          placeholder="请输入孩子姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="孩子手机号" prop="childPhoneNumber">
        <el-input
          v-model="queryParams.childPhoneNumber"
          placeholder="请输入孩子手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="孩子身份证" prop="childIdCar">
        <el-input
          v-model="queryParams.childIdCar"
          placeholder="请输入孩子身份证"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择处理状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
     <el-col :span="1.5">
       <!--      <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['receipt:userCaAppeal:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['receipt:userCaAppeal:edit']"
            >修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['receipt:userCaAppeal:remove']"
            >删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['receipt:userCaAppeal:export']"
            >导出</el-button>-->
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userCaAppealList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" v-if="false" align="center" prop="id" />
      <el-table-column label="家长姓名" align="center" prop="parentRealName" />
      <el-table-column label="家长手机号" align="center" prop="parentPhoneNumber" />
      <el-table-column label="家长身份证" align="center" prop="parentIdCar" />
      <el-table-column label="孩子姓名" align="center" prop="childRealName" />
      <el-table-column label="孩子手机号" align="center" prop="childPhoneNumber" />
      <el-table-column label="孩子身份证" align="center" prop="childIdCar" />
<!--      <el-table-column label="意见" align="center" prop="opinion" />-->
      <el-table-column label="处理状态" align="center" prop="status" :formatter="statusFormat" />
<!--      <el-table-column label="删除状态 0未删除(默认) 1已删除" align="center" prop="isDel" />-->
<!--      <el-table-column label="备注" align="center" prop="remark" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row,'check')"
            v-hasPermi="['receipt:userCaAppeal:edit']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row,'handle')" v-if="scope.row.status==1"
            v-hasPermi="['receipt:userCaAppeal:handleDealWith']"
          >处理</el-button>
<!--          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['receipt:userCaAppeal:remove']"
          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户密保申诉对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <div v-if="isDivShow">
          <el-form-item label="编号" prop="id" v-if="false">
            <el-input v-model="form.id" placeholder="id" readonly="readonly" />
          </el-form-item>
          <el-form-item label="家长姓名" prop="parentRealName">
            <el-input v-model="form.parentRealName" placeholder="请输入家长姓名" readonly="readonly" />
          </el-form-item>
          <el-form-item label="家长手机号" prop="parentPhoneNumber">
            <el-input v-model="form.parentPhoneNumber" placeholder="请输入家长手机号" readonly="readonly" />
          </el-form-item>
          <el-form-item label="家长身份证" prop="parentIdCar">
            <el-input v-model="form.parentIdCar" placeholder="请输入家长身份证" readonly="readonly" />
          </el-form-item>
          <el-form-item label="孩子姓名" prop="childRealName">
            <el-input v-model="form.childRealName" placeholder="请输入孩子姓名" readonly="readonly" />
          </el-form-item>
          <el-form-item label="孩子手机号" prop="childPhoneNumber">
            <el-input v-model="form.childPhoneNumber" placeholder="请输入孩子手机号" readonly="readonly" />
          </el-form-item>
          <el-form-item label="孩子身份证" prop="childIdCar">
            <el-input v-model="form.childIdCar" placeholder="请输入孩子身份证" readonly="readonly" />
          </el-form-item>
          <el-form-item label="反馈意见" prop="opinion">
            <el-input v-model="form.opinion" type="textarea" placeholder="请输入内容" readonly="readonly" />
          </el-form-item>
          <el-form-item label="处理状态" prop="status" v-if="false">
            <el-select v-model="form.status" placeholder="请选择处理状态">
              <el-option
                v-for="dict in statusOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="parseInt(dict.dictValue)"
              ></el-option>
            </el-select>
          </el-form-item>
        </div>
        <el-form-item label="处理意见" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer"  v-if="!isDivShow">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listUserCaAppeal, getUserCaAppeal, delUserCaAppeal, addUserCaAppeal, updateUserCaAppeal, exportUserCaAppeal } from "@/api/receipt/userCaAppeal";

export default {
  name: "UserCaAppeal",
  components: {
  },
  data() {
    return {
      auditStatus: true,
      isDivShow: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户密保申诉表格数据
      userCaAppealList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 处理状态 1未处理(默认值) 2已处理字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        parentRealName: null,
        parentPhoneNumber: null,
        parentIdCar: null,
        childRealName: null,
        childPhoneNumber: null,
        childIdCar: null,
        opinion: null,
        status: null,
        isDel: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("dict_appeal_process_status ").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    /** 查询用户密保申诉列表 */
    getList() {
      this.loading = true;
      listUserCaAppeal(this.queryParams).then(response => {
        this.userCaAppealList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 处理状态 1未处理(默认值) 2已处理字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        parentRealName: null,
        parentPhoneNumber: null,
        parentIdCar: null,
        childRealName: null,
        childPhoneNumber: null,
        childIdCar: null,
        opinion: null,
        status: null,
        isDel: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户密保申诉";
    },
    /** 修改按钮操作 */
    handleUpdate(row,rel) {
      this.reset();
      const id = row.id || this.ids
      if(rel == 'handle'){
          getUserCaAppeal(id).then(response => {
              this.form = response.data;
              this.form.status = '2'
              this.isDivShow = false;
              this.open = true;
              this.title = "处理用户密保申诉";
          });
      }else {
          getUserCaAppeal(id).then(response => {
              this.form = response.data;
              this.isDivShow = true;
              this.open = true;
              this.title = "查看用户密保申诉";
          });
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateUserCaAppeal(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUserCaAppeal(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除用户密保申诉编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delUserCaAppeal(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有用户密保申诉数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportUserCaAppeal(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
